USE Core
GO
IF OBJECT_ID('fListsHaveMatches') IS NOT NULL
BEGIN
    DROP FUNCTION fListsHaveMatches
    IF OBJECT_ID('fListsHaveMatches') IS NOT NULL
        PRINT '<<< FAILED DROPPING FUNCTION fListsHaveMatches >>>'
    ELSE
        PRINT '<<< DROPPED FUNCTION fListsHaveMatches >>>'
END
GO
CREATE FUNCTION dbo.fListsHaveMatches
(
        @list1     varchar(1024) = NULL
    ,   @list2     varchar(1024) = NULL
    ,   @delimeter varchar(20)   = NULL
)
RETURNS bit
AS
-- Description: Returns bit 1 when matching strings are found in the lists.
-- Developer: Bryan Wilhite

BEGIN
    DECLARE @bit AS bit

SET @bit = 0

IF EXISTS
(
    SELECT
        *
    FROM
        Core.dbo.fCharSplit(@list1,@delimeter) AS a
    ,   Core.dbo.fCharSplit(@list2,@delimeter) AS b
    WHERE
        a.value = b.value
)
BEGIN
    SET @bit = 1
END

RETURN @bit
END

GO
GRANT EXECUTE ON fListsHaveMatches TO public
GO
IF OBJECT_ID('fListsHaveMatches') IS NOT NULL
    PRINT '<<< CREATED FUNCTION fListsHaveMatches >>>'
ELSE
    PRINT '<<< FAILED CREATING FUNCTION fListsHaveMatches >>>'
GO
 